package com.yt.base.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yt.base.dao.AclUserDao;
import com.yt.base.model.AclUser;
import com.yt.base.service.AclUserService;
import com.yt.core.dao.filter.DynamicSQLFilterImpl;
import com.yt.core.dao.filter.QueryFilter;
import com.yt.core.service.GenericServiceImpl;

/**
 * Created by liujunshi on 15-1-28.
 */
public class AclUserServiceImpl extends GenericServiceImpl<AclUser, Long> implements AclUserService {
	private AclUserDao dao;

	public AclUserServiceImpl(AclUserDao dao) {
		super(dao);
		this.dao = dao;
	}
	
	@Override
	public AclUser findByName(String name) {
		
		return dao.findByName(name);
	}
	
	@Override
	public List<AclUser> searchByName(String name) {
		
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.addFilter("Q_name_S_LK", name);
		
		return dao.find(filter);
	}
	
	@Override
	public int countByGroup(Long groupId) {
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.addFilter("Q_groupId_L_E", String.valueOf(groupId));
		return count(filter);
	}
	@Override
	public Map<Long, AclUser> getUsersMap(String uids){
		QueryFilter filter = new DynamicSQLFilterImpl();
		filter.addFilter("Q_id_S_IN", uids);
		List<AclUser> userList = dao.find(filter);
		Map<Long, AclUser> userMap = new HashMap<Long, AclUser>();
		for(AclUser user : userList){
			userMap.put(user.getId(), user);
		}
		return userMap;
	}
}
